package keke.ai.code.mother.util;

import cn.hutool.json.JSON;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;


public class WriteJson {

    public static void writeJson(HttpServletRequest request, HttpServletResponse response, Object data) {
       response.setContentType("application/json;charset=utf-8");
       response.setHeader("Access-Control-Allow-Origin", "*");
       response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        try {
            PrintWriter writer = response.getWriter();
            writer.write(cn.hutool.json.JSONUtil.toJsonStr(data));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
